package com.coolbi.onsupai.core.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.onsupai.core.dao.CustomerDao;
import com.coolbi.onsupai.core.entity.Customer;
import com.coolbi.onsupai.core.mapper.CustomerMapper;

public class CustomerDaoImpl implements CustomerDao {

	@Autowired
	private CustomerMapper customerMapper;
	public void setCustomerMapper(CustomerMapper customerMapper) {
		this.customerMapper = customerMapper;
	}
	
	@Override
	public Customer save(Customer obj) {
		customerMapper.save(obj);
		return obj;
	}

	@Override
	public int delete(long id) {
		return customerMapper.delete(id);
	}

	@Override
	public int update(Customer obj) {
		return customerMapper.update(obj);
	}

	@Override
	public Customer get(long id) {
		return customerMapper.get(id);
	}

	@Override
	public List<Customer> list() {
		return customerMapper.list();
	}

	@Override
	public List<Customer> listByPage(int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return customerMapper.listByPage(parameter);
	}

	@Override
	public List<Customer> find(Map<String, Object> parameter) {
		return customerMapper.listByParameter(parameter);
	}

	@Override
	public List<Customer> findByPage(Map<String, Object> parameter, int offset,
			int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return customerMapper.listByParameterPage(parameter);
	}

	@Override
	public List<Customer> search(Map<String, Object> parameter, int offset, int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return customerMapper.search(parameter);
	}

	@Override
	public int count() {
		return customerMapper.count();
	}

	@Override
	public int countByKeyWord(Map<String, Object> parameter) {
		return customerMapper.countByKeyWord(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return customerMapper.countByParameter(parameter);
	}

	@Override
	public int countByTel(String tel) {
		return customerMapper.countByTel(tel);
	}

	@Override
	public int countByEmail(String email) {
		return customerMapper.countByEmail(email);
	}

	@Override
	public int countByUserName(String userName) {
		return customerMapper.countByUserName(userName);
	}

	@Override
	public int countByQQNumber(String qqNumber) {
		return customerMapper.countByQQNumber(qqNumber);
	}

	@Override
	public int updateTrade(Long id, int creditNum) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("id", id);
		parameter.put("creditNum", creditNum);
		return customerMapper.updateTrade(parameter);
	}

}
